package strauss.flatland.things.geometry;

/**
 *
 */
public class GeometricVector {
	private double deltaX;
	private double deltaY;
	/**
	 * @deprecated angular velocity must be seperate!
	 */
	private double spin2D;
	
	public GeometricVector(double deltaX, double deltaY) {
		this.deltaX = deltaX;
		this.deltaY = deltaY;
	}
	
	public GeometricVector(final Vertex a, final Vertex b) {
		this.deltaX = b.getX()-a.getX();
		this.deltaY = b.getY()-a.getY();
	}
	
	public double getXD() {
		return deltaX;
	}
	
	public double getYD() {
		return deltaY;
	}
	
	/**
	 * @deprecated angular velocity must be seperate!
	 */
	public double getSpin2D() {
		return spin2D;
	}
	
	public void setXD(double xd) {
		this.deltaX=xd;
	}
	
	public void setYD(double yd) {
		this.deltaY=yd;
	}
	
	/**
	 * @deprecated angular velocity must be seperate!
	 */
	public void setSpin2D(double spind2D) {
		this.spin2D = spind2D;
	}
	
	public void add(final GeometricVector input) {
		setXD(getXD()+input.getXD());
		setYD(getYD()+input.getYD());
	}
	
	public void add(final double scalar) {
		setXD(getXD()+scalar);
		setYD(getYD()+scalar);
	}
	
	public void multiply(final double scalar) {
		setXD(getXD()*scalar);
		setYD(getYD()*scalar);
	}
	
	public void divide(final double scalar) {
		setXD(getXD()/scalar);
		setYD(getYD()/scalar);
	}
	
	public void normalize() {
		double m = VectorMath.getMagnitude(this);
		setXD(getXD()/m);
		setYD(getYD()/m);
	}
	
	public void subtract(final double scalar) {
		setXD(getXD()-scalar);
		setYD(getYD()-scalar);
	}
	
	public void subtract(final GeometricVector a) {
		setXD(getXD()-a.getXD());
		setYD(getYD()-a.getYD());
	}
	
	public void rotate(double radian) {
		double theta = Math.acos(getXD());
		theta += radian;
		double newX = Math.cos(theta);
		setXD(newX);
		
		theta = Math.asin(getYD());
		theta += radian;
		double newY = Math.cos(theta+radian);
		setYD(newY);
	}
}
